home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 1.5 KB | 64 lines |
- package server;
-
- import java.io.*;
- import java.rmi.*;
- import java.rmi.server.*;
-
- public class DBServer extends UnicastRemoteObject
- implements DBInterface
- {
- private static final String FILE_NAME = "test.db";
- private DB db;
-
- public DBServer() throws RemoteException, IOException {
- db = new DB(FILE_NAME);
- }
-
- public synchronized void close() throws RemoteException {
- db.close();
- }
-
- public synchronized void rewind()
- throws IOException, RemoteException
- {
- db.rewind();
- }
-
- public synchronized boolean moreRecords()
- throws IOException, RemoteException
- {
- return db.moreRecords();
- }
-
- public synchronized EmployeeRecord readRecord()
- throws IOException, EOFException, RemoteException
- {
- return db.readRecord();
- }
-
- public synchronized void writeRecord(EmployeeRecord record)
- throws IOException, RemoteException
- {
- db.writeRecord(record);
- }
-
- public static void main(String[] args) {
-
- // Create and install a security manager
- System.setSecurityManager(new RMISecurityManager());
-
- try {
- DBServer dbServer = new DBServer();
-
- Naming.rebind("DBServer", dbServer);
- // located on the same machine as the client
-
- System.out.println("DBServer bound in registry");
- } catch (Exception e) {
- System.out.println("DBServer err: " + e.getMessage());
- e.printStackTrace();
- }
- }
-
- }
-